/*
    This is a set of libraries to assist in OpenGl and Other Applications
    Copyright (C) 2008  The Modular Engine Team

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
#include "EngineCore.h"
#include "WindowModule.h"
#include "OpenglModule.h"
#include "ImageLoader.h"
//#include "HUDModule.h"
#include "InterfaceModule.h"
#include <windows.h>
#include "TestModule.h"
#include "TimerModule.h"
#include "RegistryModule.h"
#include "consoleFunctions.h"
#include "ServerModule.h"
#include "ClientModule.h"
#include "GraphicsModule.h"
#include "OpenglInterface.h"

using namespace std;

int main(int argc, char *argv[])
{
	// Hide the console window
	//ShowWindow( GetConsoleWindow(), SW_HIDE );

	ModularEngine::EngineCore *engine = &ModularEngine::EngineCore::getSingleton();

	for( int i = 1; i < argc; i++ )
	{		
		if( !strcmp( argv[i], "-console" ) )
			ShowWindow( GetConsoleWindow(), SW_SHOW );
	}

	ModularEngine::WindowModule::getSingleton().setClassName( "Modular Engine" );
	ModularEngine::WindowModule::getSingleton().setWindowName( "Modular Engine" );
	ModularEngine::WindowModule::getSingleton().setDimensions( 0, 0, 1024, 768 );

//	ModularEngine::HUDModule::getSingleton().setBaseColor( ModularEngine::Vector3d( .5, .5, .5 ) );
//	ModularEngine::HUDModule::getSingleton().setTextColor( ModularEngine::Vector3d( 1, 1, 1 ) );

	ModularEngine::RegistryModule::getSingleton().setValue( "defaultRegistryFile", "registry.dat" );
	ModularEngine::RegistryModule::getSingleton().getKey( "defaultRegistryFile" ).mbSaveable = false;

	ModularEngine::GraphicsModule::getSingleton().gI = &ModularEngine::OpenglInterface::getSingleton();

	engine->loadModule(&ModularEngine::WindowModule::getSingleton());
	engine->loadModule(&ModularEngine::OpenglModule::getSingleton());
	engine->loadModule(&ModularEngine::ConsoleModule::getSingleton());
	engine->loadModule(&ModularEngine::TestModule::getSingleton());
//	engine->loadModule(&ModularEngine::HUDModule::getSingleton());
	engine->loadModule(&ModularEngine::InterfaceModule::getSingleton());
	engine->loadModule(&ModularEngine::TimerModule::getSingleton());
	engine->loadModule(&ModularEngine::RegistryModule::getSingleton());
	engine->loadModule(&ModularEngine::ServerModule::getSingleton());
	engine->loadModule(&ModularEngine::ClientModule::getSingleton());


	ModularEngine::initConsoleFunctions();

	engine->init();
	engine->run();

	ModularEngine::RegistryModule::getSingleton().saveRegistry( ModularEngine::RegistryModule::getSingleton().getKey("defaultRegistryFile")() );

	ShowWindow( GetConsoleWindow(), SW_SHOW );
}
